<%-- 
    Document   : roomType
    Created on : Jun 7, 2013, 2:24:50 PM
    Author     : Anna SAELEE
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>Tpye de chambre</title>
    </head>
    <%  Connection conn;
        Statement stmt;
        ResultSet rs, rs2, rs3;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <div class="workspace2-1">
                        <h3>List de type des chambre</h3><br/>
                        <% String sql = "SELECT tid FROM type";
                            rs = stmt.executeQuery(sql);%>
                        <table align="center" width="100%">
                            <tr>
                                <th>Type de chambre</th>
                                <th>Nombre de place</th>
                                <th>Information</th>
                            </tr>
                            <% if (rs.next()) {
                                    sql = "SELECT * FROM type";
                                    rs = stmt.executeQuery(sql);
                                    while (rs.next()) {%>
                            <tr>
                                <td><%= rs.getString("tname")%></td>
                                <td><%= rs.getString("place")%></td>
                                <td><%= rs.getString("detail")%></td>
                            </tr>
                            <% }
                            } else {%>
                            <tr>
                                <td colspan="3">Il n'y a plus de l'ensemble des résultats</td>
                            </tr>
                            <% }%>
                        </table>
                    </div>
                    <div class="workspace2-2">
                        <h3>List des chambre</h3><br/>
                        <table align="center" width="100%">
                            <tr>
                                <th>N° de chambre</th>
                                <th>Type</th>
                                <th>Etape</th>
                                <th>Personnes</th>
                                <th>Disponible</th>
                            </tr>
                            <% sql = "SELECT * FROM room";
                                rs = stmt.executeQuery(sql);
                                while (rs.next()) {%>
                            <tr>
                                <td><%=rs.getString("r_number")%></td>
                                <td><%=rs.getString("tname")%></td>
                                <td><%= rs.getString("floor")%></td>
                                <td><%= rs.getString("n_place")%></td>
                                <td><%= rs.getString("available")%></td>
                            </tr>
                            <% }%>
                        </table>
                    </div>
                    <% if (session.getAttribute("username") != null && session.getAttribute("username").equals("admin")) {
                            out.println("<div class=\"workspace2-3\">");
                            out.println("<h3>Nouveau type des chambre</h3><br/>");
                            out.println("<form method=\"post\" action=\"Enregistrer\" name=\"newRType\"/>");
                            out.println("<table width=\"100%\" align=\"center\">");
                            out.println("<input type=\"hidden\" name=\"typeMss\" value=\"newRType\"/>");
                            out.println("<tr><th>Type de chambre </th>");
                            out.println("<td><input type=\"text\" name=\"typeName\"/></td></tr>");
                            out.println("<tr><th>Nombre de place </th>");
                            out.println("<td><input type=\"text\" name=\"typePlace\" onkeypress=\"if (isNaN(this.value + String.fromCharCode(event.keyCode))) return false;\"/></td></tr>");
                            out.println("<tr><th>Information </th>");
                            out.println("<td><textarea rows=\"4\" cols=\"50\" name=\"typeInfo\"></textarea></td></tr>");
                            out.println("<tr><td colspan=\"2\" style=\"text-align: center\"><input type=\"submit\" name=\"addRType\" value=\"Ajouter nouveau type de chambre\"/></td></tr>");
                            out.println("</table>");
                            out.println("</form>");
                            out.println("</div>");

                            out.println("<div class=\"workspace2-4\">");
                            out.println("<h3>Nouvelle chambre</h3><br/>");
                            out.println("<form method=\"post\" action=\"Enregistrer\" name=\"newRoom\"/>");
                            out.println("<table width=\"100%\" align=\"center\">");
                            out.println("<input type=\"hidden\" name=\"typeMss\" value=\"newRoom\"/>");
                            out.println("<tr><th>N° de chambre </th>");
                            out.println("<td><input type=\"text\" name=\"numberRoom\"/ onkeypress=\"if (isNaN(this.value + String.fromCharCode(event.keyCode))) return false;\"/></td></tr>");
                            out.println("<tr><th>Type de chambre </th>");
                            sql = "SELECT tname FROM type";
                            rs = stmt.executeQuery(sql);
                            ArrayList<String> typeList = new ArrayList<String>();
                            while (rs.next()) {
                                typeList.add(rs.getString("tname"));
                            }
                            out.println("<td><select name=\"typeRoom\">");
                            out.println("<option>Choisir un...</option>");
                            for (int i = 0; i < typeList.size(); i++) {
                                out.println("<option value=\"" + typeList.get(i) + "\">" + typeList.get(i) + "</option>");
                            }
                            out.println("</select></td></tr>");
                            out.println("<tr><th>Etap </th><td><input type=\"text\" name=\"floorRoom\" onkeypress=\"if (isNaN(this.value + String.fromCharCode(event.keyCode))) return false;\"/></td></tr>");
                            out.println("<tr><td colspan=\"2\" style=\"text-align: center\"><input type=\"submit\" name=\"addRType\" value=\"Ajouter nouveau type de chambre\"/></td></tr>");
                            out.println("</table></form></div>");
                        }%>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }
    %>
</html>
